package top.byteio.common.mq.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.byteio.common.cache.lock.DistributedLock;
import top.byteio.common.mq.handler.MqProducerSender;
import top.byteio.common.mq.handler.RabbitMqProducerSender;
import top.byteio.common.mq.pojo.MqProperties;

/**
 * @Description: MQ配置类
 * @Author: Snail
 * @CreateDate: 2023/11/27 9:49
 * @Version: V1.0
 */
@Slf4j
@Configuration
@EnableRabbit
@EnableConfigurationProperties(MqProperties.class)
@ConditionalOnClass(RabbitAutoConfiguration.class)
public class JoleRabbitMqAutoConfig {

    @Bean
    public MessageConverter messageConverter(){
        return new Jackson2JsonMessageConverter();
    }

    @Bean("rabbitMqProducerSender")
    public MqProducerSender rabbitMqProducerSender(DistributedLock distributedLock,RabbitTemplate rabbitTemplate) {
        log.info("RabbitMqProducerSender 创建成功");
        return new RabbitMqProducerSender(distributedLock,  rabbitTemplate);
    }

}
